<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="ScreenMasterPage.master" %>
<asp:Content ContentPlaceHolderID="Head" runat="server">

	<script type="text/javascript">
		var fc;
		var host = new Host();

		function window::onload()
		{
			screen.onKey.attach(this, onKey);
			
			fc = new FrameController(mceWeather.frameElement, Agent, host);
			fc.navigate("http://10foot.scendix.com/mceWeather/current.php");
		}

		function window::unload()
		{
			screen.onKey.detach(this, onKey);
		}
		
		function onKey(sender, event)
		{
			event.refreshOSD = false;
			host.getAgent().onKey(event.keyCode);
			setTimeout(host.refresh, 50);
		}

		// This class provides external web site with all the necessary information.
		// The less information exposed the better.
		function Host()
		{
			var _agent;
			var _this = this;
			
			this.setAgent = function(agent)
			{
				_agent = agent;
			}
			this.getAgent = function()
			{
				return _agent;
			}
			
			this.onError = function(msg, url, line)
			{
				window.top.log.error("Error at line " + line + ": " + msg);
				return true;
			}

			this.refresh = function()
			{
				if(screen.getVisible())
					osh.refresh();
			}
			
			this.log = function(msg)
			{
				window.top.log.writeln(msg);
			}
		}
		
		// This class will be executed inside mceWeather web page.
		function Agent(host)
		{
			var _host = host;
			var _this = this;
			var _changeFocus;

			function initialize()
			{
				_host.setAgent(_this);
				window._agent = _this;
				// Prevent "access denied" error by hidding the window.top property name.
				window.execScript("var top = {}");
				window.onerror = onError;
				window.document.onreadystatechange = onReadyStateChange;
			}
			
			function onError(msg, url, line)
			{
				return _host.onError(msg, url, line);
			}

			function onReadyStateChange()
			{
				// Disable sounds
				window.execScript("top.strFocusSound = ''");
				window.execScript("top.strSelectSound = ''");

				if(window.document.readyState == "complete")
				{
					window.document.body.style.backgroundColor = "transparent";
					// Block built-in auto refresh.
					window.execScript("function refreshPage() {}");

					_changeFocus = changeFocus;
					window.execScript("function changeFocus(d) { window._agent.changeFocus(d); }");

					_host.refresh();
					setTimeout(_host.refresh, 1000);
				}
			}
			
			// This method helps to fix a bug with highlighting of buttons when OSH Host does not have the focus.
			// It updates the current element's class name removing "_hilite" suffix.
			this.changeFocus = function(direction)
			{
				var _curFocus = oCurFocus;
				if(_changeFocus)
					_changeFocus(direction);
				if(_curFocus != oCurFocus)
				{
					var className = _curFocus.className;
					if(className.substring(className.length-7) == "_hilite")
						_curFocus.className = className.substring(0, className.length-7);
				}
			}
			
			this.onKey = function(keyCode)
			{
				onRemoteEvent(keyCode);
			}
			
			initialize();
		}

	</script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Body" runat="server">

	<iframe id="mceWeather" src="about:blank" allowtransparency="true"></iframe>

</asp:Content>
